Const PROG_VERSION:Short = 1
Global ProjectFolder:String = "Projects"

If FileType(ProjectFolder) <> 2 Then
	Print "Error: Invalid Project Folder!"
	End
EndIf

AppTitle = "LQuest Project Manager"

PrintVersion()
Print "---"
Print "~t~qHelp~q for a list of commands"
Local command:String = Input("> ").ToLower()
While command <> "quit" And command <> "exit"
	Select command
		Case "help"
			PrintHelp()
		Case "new"
			NewProject()
		Case "list"
			ListProjects()
		Case "version"
			PrintVersion()
		Default
			Print "Unknown Command: " + command
	End Select
	command = Input("> ").ToLower()
Wend
End

Function PrintHelp()
	Print "new"
	Print "~tCreate a new project"
	Print
	Print "list"
	Print "~tLists all projects in projects directory"
	Print
	Print "version"
	Print "~tDisplays the release information for this build"
	Print
	Print "quit|exit"
	Print "~tExits from this prompt, and closes this program"
	Print
	Print "help"
	Print "~tDisplays this help"
End Function

Function NewProject()
	Local projectName:String = Input("New Project Name > ")
	If FileType(ProjectFolder + "/" + projectName) = 2 Then
		Print "Project Already Exists!"
		Return
	EndIf
	CreateDir(ProjectFolder + "/" + projectName + "/Data/Zones",True)
	If FileType(ProjectFolder + "/" + projectName) <> 2 Then
		Print "Unable to create directory for project ~q" + projectName + "~q"
		Print "Run this prompt as Administrator (Windows) or check permissions of projects directory (Other Platforms)"
		Return
	EndIf
	CreateDir(ProjectFolder + "/" + projectName + "/Assets/Scripts",True)
	Local file:TStream = LittleEndianStream(WriteFile(ProjectFolder + "/" + projectName + "/project.dat"))
	file.WriteShort(PROG_VERSION)
	file.WriteInt(Len(projectName));file.WriteString(projectName)
	file.Close()
End Function

Function ListProjects()
	Local dir = ReadDir(ProjectFolder)
		Repeat
			Local file:String = NextFile(dir)
			If file = "" Then Exit
			If file = "." Or file = ".." Then Continue
			If FileType(ProjectFolder + "/" + file) = 2 And FileType(ProjectFolder + "/" + file + "/project.dat") = 1 Then Print file
		Forever
	CloseDir dir
End Function

Function PrintVersion()
	Print "LQuest Project Manager v" + PROG_VERSION
End Function